<style>
#shiftingEditPageContent dl span.error {
    position: absolute;
    left: 260px;
}
</style>
<div class="pageContent">
    <form class="pageForm required-validate">
        <div class="pageFormContent" id="shiftingEditPageContent">
            <input type="hidden" name="navTabId" value="${navTabId}"> 
            <input type="hidden" name="id" value="${shifting.id}">
            <fieldset>
                <dl>
                    <dt>工作中心：</dt>
                    <dd>
                        <input name="workcenterText" value="${shifting.workcenterText}" size="22" type="text" maxlength="60" readonly="readonly"/>
                    </dd>
                </dl>
                <dl>
                    <dt>人员编号：</dt>
                    <dd>
                        <input name="personnelCode" value="${shifting.personnelCode}" size="22" type="text" maxlength="60" readonly="readonly"/>
                    </dd>
                </dl>
                <dl>
                    <dt>姓名：</dt>
                    <dd>
                        <input name="personnelName" value="${shifting.personnelName}" readonly="readonly" size="22" type="text" maxlength="60" />
                        <input name="workcenterCode" value="${shifting.workcenterCode}" type="hidden" />
                    </dd>
                </dl>
                <dl>
                    <dt>日期：</dt>
                    <dd>
                        <input id="theDate" name="theDate" value='${(shifting.theDate?string("yyyy-MM-dd"))?if_exists}' size="22" formate type="text" maxlength="60" class="readonly" />
                    </dd>
                </dl>
                <!-- <dl>
                    <dt>人员类型：</dt>
                    <dd>
                        <select name="personnelTypeCode" class="required">
                            <#list ptas as pta>
                            <option value='${pta.personnelTypeCode}'
                            <#if pta.personnelTypeCode == shifting.personnelTypeCode>selected="selected"</#if>
                            >${pta.typeText}</option> 
                            </#list>
                        </select>
                    </dd>
                </dl> -->
                <dl>
                    <dt><@label key="shiftingWorkCenter.C,colon">实际工作中心</@label></dt>
                    <dd>
                        <select name="shiftingWorkcenterCode" class="required"> 
                            <#list permissions as permission>
                            <option value='${permission.workcenterCode}'
                            <#if permission.workcenterCode == shifting.shiftingWorkcenterCode>selected="selected"</#if>
                            >${permission.workcenterText}</option> 
                            </#list>
                        </select>
                    </dd>
                </dl>
                <dl>
                    <dt>选择时段：</dt>
                    <dd>
                        <select id="periodSelect"></select>
                    </dd>
                </dl>
                <dl>
                    <dt>开始时间：</dt>
                    <dd>
                        <input name="startDateTime" size="22" formate type="text" value='${(shifting.startDateTime?string("yyyy-MM-dd HH:mm"))?if_exists}' dateFmt="yyyy-MM-dd HH:mm" dateGroup="dateTime" class="required date from" /> <a class="inputDateButton" href="javascript:;" />
                    </dd>
                </dl>
                <dl>
                    <dt>结束时间：</dt>
                    <dd>
                        <input name="endDateTime" size="22" formate type="text" value='${(shifting.endDateTime?string("yyyy-MM-dd HH:mm"))?if_exists}' dateFmt="yyyy-MM-dd HH:mm" dateGroup="dateTime" class="required date to" /> <a class="inputDateButton" href="javascript:;" />
                    </dd>
                </dl>
                <!-- <dl>
                    <dt>物料编号：</dt>
                    <dd>
                        <input size="22" type="text" maxlength="60" value="${shifting.materialCode}" class="required" name="materialCode" type="text" postField="materialCode" 
                        id="materialLookup.materialCode"
                        suggestFields="materialCode,materialText" 
                        suggestUrl="${rc.getContextPath()}/manage/material/componentSuggest" 
                        remote="${rc.getContextPath()}/manage/material/validateMaterial" 
                        warn="<@label key='materialCodeNotExists.M'>物料不存在</@label>" lookupGroup="materialLookup" /> 
                        <input type="hidden" id="materialLookup.materialText" name="materialText" />
                    </dd>
                </dl> -->
                <dl>
                    <dt>备注：</dt>
                    <dd>
                        <input name="memo" value="${shifting.memo}" size="22" type="text" maxlength="60" />
                    </dd>
                </dl>
            </fieldset>
        </div>
        <#if shifting??>
            <#assign createInfo=shifting>
            <#include "/common/createInfo.html">
        </#if>
        <div class="formBar">
            <ul>
                <li>
                    <div class="buttonActive">
                        <div class="buttonContent">
                            <button id="saveShifting" type="button"><@label key="save.B">保存</@label></button>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="buttonActiveGrey">
                        <div class="buttonContent">
                            <button type="button" class="close"><@label key="cancel.B">取消</@label></button>
                        </div>
                    </div>
                </li>
            </ul>
        </div>
    </form>
</div>
<ul id="closeBtn" style="float: right; margin: 10px 0px; display: none;">
    <li style="float: right;">
        <div class="buttonActive">
            <div class="buttonContent">
                <button type="button" class="close"><@label key="close.B">关闭</@label></button>
            </div>
        </div>
    </li>
</ul>
<span id="errorMsg" style="height: 30px; line-height: 30px; color: red; font-size: 13px; display: none;"></span>
<script type="text/javascript">
(function($){
    var $page = DWZ.context(), $parentGrid = $('#jGridForShifting', $page.data("_parent")), $form = $('form:first', $page), 
    $start = $('[name=startDateTime]', $form), $end = $('[name=endDateTime]', $form), $shiftingWorkcenter = $('[name=shiftingWorkcenterCode]', $form),
    dateFormat = 'yyyy-MM-dd', dateTimeFormat= 'yyyy-MM-dd HH:mm', perDay = 24 * 60 * 60 * 1000, common = ShiftingCommon();
    common.initPage($page, true);
    $('#saveShifting', $page).on('click', function(){
        var $this = $(this), postData = {};
        if ($form && $form.valid()) {
            $.each($form.serializeArray(), function(){
                if (this.name == 'theDate' || this.name == 'startDateTime' || this.name == 'endDateTime') {
                    postData[this.name] = this.value.parseDate(dateTimeFormat);
                } else {
                    postData[this.name] = this.value;
                }
            });
            if (postData.startDateTime.getTime() >= postData.endDateTime.getTime() || postData.endDateTime.getTime() - postData.startDateTime.getTime() > perDay) {
                alertMsg.error('起止时间不合法！');
                return false;
            }
            //postData.personnelTypeText = $('>option:eq(' + $personnelType[0].selectedIndex + ')', $personnelType).text();
            postData.shiftingWorkcenterText = $('>option:eq(' + $shiftingWorkcenter[0].selectedIndex + ')', $shiftingWorkcenter).text();
            if (!common.validate(postData)) {
                DWZ.ajax({
                    url: '${rc.getContextPath()}/manage/shifting/saveShifting',
                    type: 'POST',
                    data: postData,
                    dataType: 'json',
                    success: function(json) {
                        $parentGrid.jGrid('loadData');
                    }
                });
                $.pdialog.close($page);
            }
        }
    });
})(jQuery);
</script>